/**
 * Created by kamlyli on 2017/7/22.
 */

import API from '../interfaces/api'
import UiUtil from './uiUtil'

// 登录
function login () {
  return new Promise(function (resolve, reject) {
    wx.login({
      success: function (res) {
        // console.log(res)
        resolve(res)
      },
      fail: function (res) {
        // console.log(res)
        resolve(res)
      }
    })
  })
}

// 获取cookie
async function getCookie (code, rawData, signature, encryptedData, iv) {
  const data = await API.getCookie(code, rawData, signature, encryptedData, iv)
  return data
}

// 获取用户信息
function getUserInfo () {
  return new Promise(function (resolve, reject) {
    wx.getUserInfo({
      success: function (res) {
        // console.log(res)
        resolve(res)
      },
      fail: function (res) {
        // console.log(res)
        reject(res)
      }
    })
  })
}

// 获取系统信息
function getSystemInfo () {
  return new Promise(function (resolve, reject) {
    wx.getSystemInfo({
      success: function (res) {
        resolve(res)
      },
      fail: function (res) {
        reject(res)
      }
    })
  })
}

module.exports = {
  UiUtil,
  login,
  getUserInfo,
  getCookie,
  getSystemInfo
}
